package com.file.system.entity.listener;

import cn.hutool.json.JSONUtil;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class CustomEventListener {

    @EventListener(CustomEvent.class)
    public void onApplicationEvent1(CustomEvent customEvent) {
        System.out.println("监听器接受消息1：" + JSONUtil.toJsonStr(customEvent));
        System.out.println("监听器接受消息1：" + customEvent.getTimestamp());
        System.out.println("接收到的消息为1：" + customEvent.getMessage());
    }

    @Async
    @EventListener(CustomEvent1.class)
    public void onApplicationEvent1(CustomEvent1 customEvent)  {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("监听器接受消息2：" + JSONUtil.toJsonStr(customEvent));
        System.out.println("监听器接受消息2：" + customEvent.getTimestamp());
        System.out.println("接收到的消息为2：" + customEvent.getMessage());
    }
}